<!--
 * @Description:
 * @Author: zhaolei
 * @Date: 2023-04-15 10:20:42
-->
<template>
  <basic-container>
    <avue-crud
      ref="crud"
      v-model="form"
      :page.sync="page"
      :data="tableData"
      :table-loading="tableLoading"
      :option="tableOption"
      @on-load="getList"
      @search-change="searchChange"
      @search-reset="searchReset"
    >
      <template slot="menuLeft">
      </template>
      <template
        slot="menu"
        slot-scope="scope"
      >
        <el-button
          type="text"
          size="small"
          icon="el-icon-delete"
          @click="look(scope.row, scope.index)"
        >查看
        </el-button>
      </template>
    </avue-crud>
    <detailPopup
      :id="id"
      v-model="detailVisible"
    ></detailPopup>
  </basic-container>
</template>

<script>
import { fetchList } from '@/api/core/pet-file';
import { tableOption } from '@/const/crud/customer/pet-file';
import { mapGetters } from 'vuex';
import crudMixins from '@/mixins/crud';
import detailPopup from './components/detailPopup.vue';
export default {
  name: 'petFile',
  components: { detailPopup },
  mixins: [crudMixins],
  data() {
    return {
      detailVisible: false,
      form: {},
      tableOption: tableOption(),
      id: null,
    };
  },
  computed: {
    ...mapGetters(['permissions']),
  },
  watch: {},
  methods: {
    look(row) {
      this.id = row.id;
      this.detailVisible = true;
    },
    // 列表查询
    getList(page, refresh) {
      // console.log(12, this.searchForm.petType);
      if (!this.validatenull(this.searchForm.petType)) {
        this.searchForm.typeCode = this.searchForm.petType[0] || '';
        this.searchForm.varietyCode = this.searchForm.petType[1] || '';
      }
      if (refresh) {
        this.page.current = 1;
        this.page.currentPage = 1;
      }
      this.tableLoading = true;
      const timeObj = {};
      if (this.searchForm.arrivalDate && this.searchForm.arrivalDate.length) {
        timeObj.arrivalDateStart = this.searchForm.arrivalDate[0];
        timeObj.arrivalDateEnd = this.searchForm.arrivalDate[1];
        // delete this.searchForm.arrivalDate;
      }
      fetchList(
        Object.assign(
          {
            current: this.page.currentPage,
            size: this.page.pageSize,
          },
          this.searchForm,
          timeObj
        )
      )
        .then((response) => {
          this.tableData = response.data.data.records;
          this.page.total = response.data.data.total;
          this.tableLoading = false;
          this.tableData.forEach((el) => {
            el.petType = [el.typeCode, el.varietyCode];
            // el.avatar =
            //   'https://img.alicdn.com/tfs/TB1v28TC8v0gK0jSZKbXXbK2FXa-1880-640.jpg';
          });
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },
    //  导出excel
    exportExcel() {
      this.downBlobFile('/app/appuser/export', this.searchForm, 'appuser.xlsx');
    },
  },
};
</script>
